<!DOCTYPE html>
<html lang="en">
<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="David的博客 |  David&#39;s Blog">
    <meta name="keyword" content="程序员小冰 David&#39;s Blog">
    <link rel="shortcut icon" href="/blog/img/favicon.ico">

    <title>
        
        【Docker】docker常用命令总结大全 - David 的博客 | David&#39;s Blog
        
    </title>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/blog/css/aircloud.css">
    <link rel="stylesheet" href="/blog/css/gitment.css">
    <!--<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">-->
    <link href="//at.alicdn.com/t/font_620856_pl6z7sid89qkt9.css" rel="stylesheet" type="text/css">
    <!-- ga & ba script hoook -->
    <script></script>
</head>

<body>

<div class="site-nav-toggle" id="site-nav-toggle">
    <button>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
    </button>
</div>

<div class="index-about">
    <i> David Blog </i>
</div>

<div class="index-container">
    
    <div class="index-left">
        
<div class="nav" id="nav">
    <div class="avatar-name">
        <div class="avatar radius">
            <img src="/blog/img/avatar.jpg" />
        </div>
        <div class="name">
            <i>David</i>
        </div>
    </div>
    <div class="contents" id="nav-content">
        <ul>
            <li >
                <a href="/blog/">
                    <i class="iconfont icon-shouye1"></i>
                    <span>主页</span>
                </a>
            </li>
            <li >
                <a href="/blog/tags">
                    <i class="iconfont icon-biaoqian1"></i>
                    <span>标签</span>
                </a>
            </li>
            <li >
                <a href="/blog/archives">
                    <i class="iconfont icon-guidang2"></i>
                    <span>存档</span>
                </a>
            </li>
            <li >
                <a href="/blog/about/">
                    <i class="iconfont icon-guanyu2"></i>
                    <span>关于</span>
                </a>
            </li>
            
            <li>
                <a id="search">
                    <i class="iconfont icon-sousuo1"></i>
                    <span>搜索</span>
                </a>
            </li>
            
        </ul>
    </div>
    
        <div id="toc" class="toc-article">
    <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#docker命令的具体使用参数帮助"><span class="toc-text">docker命令的具体使用参数帮助</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#查看当前正在运行的容器"><span class="toc-text">查看当前正在运行的容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#查看所有容器的状态。最近运行过的所有容器"><span class="toc-text">查看所有容器的状态。最近运行过的所有容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#启动-停止某个容器"><span class="toc-text">启动/停止某个容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#进入某个容器-使用exit退出后容器也跟着停止运行"><span class="toc-text">进入某个容器(使用exit退出后容器也跟着停止运行)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#启动一个伪终端以交互式的方式进入某个容器"><span class="toc-text">启动一个伪终端以交互式的方式进入某个容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#查看本地镜像"><span class="toc-text">查看本地镜像</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#删除某个容器"><span class="toc-text">删除某个容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#删除某个镜像"><span class="toc-text">删除某个镜像</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#有时候删除会失败，比如：有一个容器正在使用该镜像文件。这时可以加参数-f-强制删除"><span class="toc-text">有时候删除会失败，比如：有一个容器正在使用该镜像文件。这时可以加参数-f 强制删除</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#复制ubuntu容器并且重命名为test且运行，然后以伪终端交互式方式进入容器，运行bash"><span class="toc-text">复制ubuntu容器并且重命名为test且运行，然后以伪终端交互式方式进入容器，运行bash</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Docker容器中使用vi编辑器"><span class="toc-text">Docker容器中使用vi编辑器</span></a></li></ol>
</div>
    
</div>


<div class="search-field" id="search-field">
    <div class="search-container">
        <div class="search-input">
            <span id="esc-search"> <i class="icon-fanhui iconfont"></i></span>
            <input id="search-input"/>
            <span id="begin-search">搜索</span>
        </div>
        <div class="search-result-container" id="search-result-container">

        </div>
    </div>
</div>

        <div class="index-about-mobile">
            <i> David Blog </i>
        </div>
    </div>
    
    <div class="index-middle">
        <!-- Main Content -->
        


<div class="post-container">
    <div class="post-title">
        【Docker】docker常用命令总结大全
    </div>

    <div class="post-meta">
        <span class="attr">发布于：<span>2020-06-21 10:58:57</span></span>
        
        <span class="attr">标签：/
        
        <a class="tag" href="/blog/tags/#Docker" title="Docker">Docker</a>
        <span>/</span>
        
        
        </span>
        <span class="attr">访问：<span id="busuanzi_value_page_pv"></span>
</span>
</span>
    </div>
    <div class="post-content ">
        <h5 id="docker命令的具体使用参数帮助"><a href="#docker命令的具体使用参数帮助" class="headerlink" title="docker命令的具体使用参数帮助"></a>docker命令的具体使用参数帮助</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker 命令 --help</span><br></pre></td></tr></table></figure>

<h5 id="查看当前正在运行的容器"><a href="#查看当前正在运行的容器" class="headerlink" title="查看当前正在运行的容器"></a>查看当前正在运行的容器</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps</span><br></pre></td></tr></table></figure>

<h5 id="查看所有容器的状态。最近运行过的所有容器"><a href="#查看所有容器的状态。最近运行过的所有容器" class="headerlink" title="查看所有容器的状态。最近运行过的所有容器"></a>查看所有容器的状态。最近运行过的所有容器</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps -a</span><br></pre></td></tr></table></figure>

<h5 id="启动-停止某个容器"><a href="#启动-停止某个容器" class="headerlink" title="启动/停止某个容器"></a>启动/停止某个容器</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start/stop id/name</span><br></pre></td></tr></table></figure>

<h5 id="进入某个容器-使用exit退出后容器也跟着停止运行"><a href="#进入某个容器-使用exit退出后容器也跟着停止运行" class="headerlink" title="进入某个容器(使用exit退出后容器也跟着停止运行)"></a>进入某个容器(使用exit退出后容器也跟着停止运行)</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker attach id</span><br></pre></td></tr></table></figure>

<h5 id="启动一个伪终端以交互式的方式进入某个容器"><a href="#启动一个伪终端以交互式的方式进入某个容器" class="headerlink" title="启动一个伪终端以交互式的方式进入某个容器"></a>启动一个伪终端以交互式的方式进入某个容器</h5> <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker  exec -it   9af8c6c13cb4（容器ID）   /bin/bash</span><br></pre></td></tr></table></figure>

<h5 id="查看本地镜像"><a href="#查看本地镜像" class="headerlink" title="查看本地镜像"></a>查看本地镜像</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>

<h5 id="删除某个容器"><a href="#删除某个容器" class="headerlink" title="删除某个容器"></a>删除某个容器</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rm id/name</span><br></pre></td></tr></table></figure>

<h5 id="删除某个镜像"><a href="#删除某个镜像" class="headerlink" title="删除某个镜像"></a>删除某个镜像</h5><h6 id="有时候删除会失败，比如：有一个容器正在使用该镜像文件。这时可以加参数-f-强制删除"><a href="#有时候删除会失败，比如：有一个容器正在使用该镜像文件。这时可以加参数-f-强制删除" class="headerlink" title="有时候删除会失败，比如：有一个容器正在使用该镜像文件。这时可以加参数-f 强制删除"></a>有时候删除会失败，比如：有一个容器正在使用该镜像文件。这时可以加参数-f 强制删除</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rmi id/name</span><br></pre></td></tr></table></figure>

<h5 id="复制ubuntu容器并且重命名为test且运行，然后以伪终端交互式方式进入容器，运行bash"><a href="#复制ubuntu容器并且重命名为test且运行，然后以伪终端交互式方式进入容器，运行bash" class="headerlink" title="复制ubuntu容器并且重命名为test且运行，然后以伪终端交互式方式进入容器，运行bash"></a>复制ubuntu容器并且重命名为test且运行，然后以伪终端交互式方式进入容器，运行bash</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run --name test -ti ubuntu /bin/bash</span><br></pre></td></tr></table></figure>

<h5 id="Docker容器中使用vi编辑器"><a href="#Docker容器中使用vi编辑器" class="headerlink" title="Docker容器中使用vi编辑器"></a>Docker容器中使用vi编辑器</h5><figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">apt-<span class="built_in">get</span> <span class="keyword">update</span></span><br><span class="line">apt-<span class="built_in">get</span> install <span class="keyword">vi</span></span><br><span class="line"></span><br><span class="line">这个命令的作用是：同步 /etc/apt/sources.<span class="keyword">list</span> 和 /etc/apt/sources.<span class="keyword">list</span>.d 中列出的源的索引，这样才能获取到最新的软件包。安装V编辑器。</span><br></pre></td></tr></table></figure>


        
            <div class="donate-container">
    <div class="donate-button">
        <button id="donate-button">赞赏</button>
    </div>
    <div class="donate-img-container hide" id="donate-img-container">
        <img id="donate-img" src="" data-src="/blog/img/donate.jpg">
        <p> 感谢鼓励 </p>
    </div>
</div>
        
        <br />
        <div id="comment-container">
        </div>
        <div id="disqus_thread"></div>

        <div id="lv-container">
        </div>

    </div>
</div>

    </div>
</div>


<footer class="footer">
    <ul class="list-inline text-center">
        
        <li>
            <a target="_blank" href="https://twitter.com/qq986945193">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-twitter"></i>
                            </span>
            </a>
        </li>
        
        
        <li>
            <a target="_blank" href="https://www.zhihu.com/people/mcxiaobing">
                            <span class="fa-stack fa-lg">
                                 <i class="iconfont icon-zhihu"></i>
                            </span>
            </a>
        </li>
        

        
        <li>
            <a target="_blank" href="http://weibo.com/mcxiaobing">
                            <span class="fa-stack fa-lg">
                                  <i class="iconfont icon-weibo"></i>
                            </span>
            </a>
        </li>
        

        
        <li>
            <a target="_blank" href="https://www.facebook.com/qq986945193">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-facebook"></i>
                            </span>
            </a>
        </li>
        

        
        <li>
            <a target="_blank"  href="https://github.com/qq986945193">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-github"></i>
                            </span>
            </a>
        </li>
        

        

    </ul>
    
    <p>
        <span>/</span>
        
        <span><a href="https://segmentfault.com/u/mcxiaobing">思否</a></span>
        <span>/</span>
        
        <span><a href="https://juejin.im/user/57edcdb2a0bb9f0058ed8ed9">掘金</a></span>
        <span>/</span>
        
        <span><a href="https://www.jianshu.com/u/4e2015c5a972">简书</a></span>
        <span>/</span>
        
        <span><a href="https://gitee.com/mcxiaobing">码云</a></span>
        <span>/</span>
        
    </p>
    
    <p>
        <span id="busuanzi_container_site_pv">
            <span id="busuanzi_value_site_pv"></span>PV
        </span>
        <span id="busuanzi_container_site_uv">
            <span id="busuanzi_value_site_uv"></span>UV
        </span>
        Created By <a href="https://hexo.io/">Hexo</a>  Theme <a href="https://github.com/aircloud/hexo-theme-aircloud">AirCloud</a></p>
</footer>




</body>

<script>
    // We expose some of the variables needed by the front end
    window.hexo_search_path = "search.json"
    window.hexo_root = "/blog/"
    window.isPost = true
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="/blog/js/index.js"></script>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




</html>
